from rest_framework.pagination import LimitOffsetPagination, CursorPagination, PageNumberPagination


# 基本分页 常用
class CommonPageNumberPagination(PageNumberPagination):
    page_size = 20  # 每页显示条数
    page_query_param = 'page'  # 查询时用的参数url/?page=2
    page_size_query_param = 'size'  # url/?page=1&size=4  更改返回条数，第一页返回四条
    max_page_size = 100  # 一页最多显示50条


# 偏移分页
class CommonLimitOffsetPagination(LimitOffsetPagination):
    default_limit = 20
    limit_query_param = 'limit'  # limit的参数url/?limit=2&offset=4
    offset_query_param = 'offset'  # offset偏移的查询参数urls/?limit=2&offset=4
    max_limit = 100  # 最大显示条数，为5


# 游标分页
class CommonCursorPagination(CursorPagination):
    cursor_query_param = 'c'  # 查询条件
    page_size = 20  # 每页显示多少条
    ordering = '-id'  # 排序，按id倒序
    page_size_query_param = 'size'  # 通过这个参数决定每页显示多少条
    max_page_size = 100  # 每页最大显示多少条
